package com.lb.shopguide.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;

import com.lb.shopguide.GuideApplication;
import com.lb.shopguide.R;

/**
 * Created by kang on 2017/10/21.
 */

public class LayoutActivityFlag extends LinearLayout {
    public LayoutActivityFlag(Context context) {
        super(context);
    }

    public LayoutActivityFlag(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setActivityFlag(String flags) {
        removeAllViews();
        String[] flagArray = flags.split(",");
        for (int i = 0; i < flagArray.length; i++) {
            addFlag(flagArray[i]);
        }
    }

    private void addFlag(String flag) {
        LbFontTextView textView = new LbFontTextView(getContext());
        textView.setText(flag);
        textView.setGravity(Gravity.CENTER);
        textView.setId(R.id.textView);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
        textView.setTextColor(getResources().getColor(R.color.white));
        textView.setPadding((int) (5 * GuideApplication.getAppContext().getResources().getDisplayMetrics().density), 0,
                (int) (5 * GuideApplication.getAppContext().getResources().getDisplayMetrics().density), 0);
        textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_round_corner_activity));
        textView.setMinWidth((int) (17 * GuideApplication.getAppContext().getResources().getDisplayMetrics().density));
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
                (int) (14 * GuideApplication.getAppContext().getResources().getDisplayMetrics().density));
        params.setMargins(0, 0, (int) (10 * GuideApplication.getAppContext().getResources().getDisplayMetrics().density), 0);
        addView(textView, params);
    }
}
